package l3.info.Projet.Client;


import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import l3.info.Projet.RMI.RequetesReseau;

/**
 * This is a simple print client.
 * 
 * @author Aboulkacem Hamid
 */
public class RequetesClient {
	private static RequetesReseau connexionServer = null;

	public RequetesClient() throws NotBoundException {
		if (connexionServer == null) {
			//System.setSecurityManager(new RMISecurityManager());
			// Registry registry = LocateRegistry.getRegistry("localhost");
			try {
				connexionServer = (RequetesReseau) Naming.lookup("serveur");
			} catch (MalformedURLException ex) {
				// TODO Auto-generated catch block
				// ex.printStackTrace();
			} catch (RemoteException ex) {
				// TODO Auto-generated catch block
				// ex.printStackTrace();
			}
		}
	}

	public RequetesReseau getReseau() {
		return connexionServer; 
	}

	public void envoyerUtilisateur(Utilisateur u) {
		try {
			// getReseau().printUtilisateur(u);
			getReseau().utilisateurExists(u);
			// System.out.println(u.getConnexion()); NOK !!!
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			System.err.println("Echec d'envoi \n"+ e.getMessage());
		}
	}
}